﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Prototype.Dialogs
{
    public partial class NewProject : Form
    {
        protected NewProjectInfo projectInfo = new NewProjectInfo();
        public NewProjectInfo ProjectInfo
        {
            get { return projectInfo; }
        }

        public NewProject()
        {
            InitializeComponent();

            // Get information on the packages directory
            string appDir = Application.StartupPath;
            string pkgDirPath = appDir + "\\Packages";
            DirectoryInfo pkgDir = new DirectoryInfo(pkgDirPath);

            // Search every directory in the packages directory for files with "pep" extension
            FileInfo[] pkgFiles = pkgDir.GetFiles("*pep", SearchOption.AllDirectories);
            foreach (FileInfo file in pkgFiles)
            {
                string pkgText = file.FullName.Substring(appDir.Length);

                listPackages.Items.Add(pkgText);
            }
        }

        // The contents of the project name text box has been changed
        private void txtProjectName_TextChanged(object sender, EventArgs e)
        {
            // Enable the finish button if the project name isn't empty
            if (txtProjectName.Text.Length > 0)
            {
                btnCreateProject.Enabled = true;
            }
            else // Otherwise disable the finish button if the project name is empty
            {
                btnCreateProject.Enabled = false;
            }
        }

        // The create project button has been pressed
        private void btnCreateProject_Click(object sender, EventArgs e)
        {
            // Create project directory and add any packaged assets
            projectInfo.Name = txtProjectName.Text;

            // Add packages to projectInfo
            projectInfo.Packages = new List<string>();
            for (int i = 0; i < listPackages.CheckedItems.Count; i++)
            {
                projectInfo.Packages.Add(listPackages.CheckedItems[i].ToString());
            }

            // Set dialog result to ok then close this dialog
            DialogResult = DialogResult.OK;
            Close();
        }
    }

    public class NewProjectInfo
    {
        public string Name;
        public List<string> Packages;
    }
}
